<template>
	<view class="address-container">
		<view class="address-btn" v-if="JSON.stringify(address) === '{}'">
			<button type="primary" size="mini" @click="chooseAddress">请选择收货地址+</button>
		</view>
		<view class="address-info" v-else @click="chooseAddress">
			<view class="row1">
				<view class="row1-left">
					<view class="label">
						收货人：
						<text class="content">
							{{address.userName}}
						</text>
					</view>
				</view>
				<view class="row1-right">
					<view class="label">
						电话：
						<text class="content">
							{{address.telNumber}}
						</text>
					</view>
					<uni-icons type="arrowright" size="16"></uni-icons>
				</view>
			</view>
			<view class="row2">
				<view class="label">
					收货地址：
					<text class="content">
						{{addstr}}
					</text>
				</view>
			</view>
		</view>
		<image class="cart-line" src="../../static/cart_border@2x.png"></image>
	</view>
</template>

<script>
	import { mapState, mapMutations, mapGetters } from 'vuex'
	export default {
		name:"my-address",
		data() {
			return {
			};
		},
		computed: {
			...mapState('m_user', ['address']),
			...mapGetters('m_user', ['addstr'])
		},
		methods: {
			...mapMutations('m_user', ['updateAddress']),
			async chooseAddress() {
				const [err, succ] = await uni.chooseAddress().catch(err => err)
				console.log('qqq', [err, succ])
				if(err === null && succ.errMsg === 'chooseAddress:ok') {
					// this.address = succ
					this.updateAddress(succ)
				}
				// 用户没有授权
				if(err && err.errMsg === 'chooseAddress:fail auth deny') {
					this.reAuth() // 向用户重新发起授权申请
				}
				// 用户授权 https://www.bilibili.com/video/BV1834y1676P?p=162&spm_id_from=pageDriver&vd_source=69379ff41d9234cc19b813520bec93b3  p162
			}
		}
	}
</script>

<style lang="scss">
.address-container {
	.address-btn {
		height: 90px;
		display: flex;
		justify-content: center;
		align-items: center;
		button {
		}
	}
	.address-info {
		font-size: 12px;
		.row1, .row1-right {
			display: flex;
		}
		.row1 {
			justify-content: space-between;
		}
		.label {
			height: 30px;
		}
	}
	.cart-line {
		height: 5px;
	    width: 100%;
		display: block;
	}
}
</style>